package initialize

import (
	"go.uber.org/zap"
	query_service "mine-info-server/app/command_service"
	"mine-info-server/config"
	"mine-info-server/global"
)

func Timer() {
	if global.GVA_CONFIG.Timer.Start {
		for i := range global.GVA_CONFIG.Timer.Detail {
			go func(detail config.Detail) {
				global.GVA_LOG.Info("定时任务启动", zap.String("task", detail.DealFlag))
				switch detail.DealFlag {
				// 周六晚上十二点执行
				case "sunday_plan_reminder":
					global.GVA_Timer.AddTaskByFunc("sunday_plan_reminder", "@weekly", func() {
						err := query_service.SundayPlanReminderHandler()
						if err != nil {
							global.GVA_LOG.Error(err.Error())
						}
					})
				}

			}(global.GVA_CONFIG.Timer.Detail[i])
		}
	}
}
